package com.example.taobaounion.ui.widget

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.View
import androidx.core.widget.NestedScrollView

/**
 *@author : Administrator
 *@descreption : 自定义继承NestedScrollView,让RecyclerView上面的view也一起滑动
 */
class MyNestedScrollView : NestedScrollView {
    private var mVerticalChange: Int = 0
    private var mHeardHeight: Int = 0

    constructor(context: Context) : super(context)
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    fun setHeardHeight(height:Int){
        this.mHeardHeight = height
    }

    override fun onNestedPreScroll(
        target: View, dx: Int, dy: Int, consumed: IntArray,
        type: Int
    ) {
        if (mVerticalChange<mHeardHeight){
            scrollBy(dx,dy)
/*            consumed[0] = dx
            consumed[1] = dy*/
        }
       super.onNestedPreScroll(target, dx, dy, consumed, type)
    }

/*    override fun onNestedScroll(target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int, consumed: IntArray) {
        Log.i("TAG", "dy====>>>>>>$dyConsumed ");
        super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, type, consumed)
    }*/

    override fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) {
         mVerticalChange = t
        super.onScrollChanged(l, t, oldl, oldt)
    }
}